package cn.usian.controller;

import cn.usian.pojo.User;
import cn.usian.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class UserController {
    @Resource
    private UserService userService;

    @RequestMapping("findAll")
    public String findAll(Model model,String searchMap){

        List<User>list=userService.findAll(searchMap);
        model.addAttribute("list",list);
        return "user";
    }

    @RequestMapping("toadd")
    public String toadd(){
        return "add";
    }

    @RequestMapping("add")
    public String add(User user){
        userService.add(user);
        return "redirect:/findAll";
    }

    //回显
    @RequestMapping("findById")
    public String findById(Long id,Model model){
        User user=userService.findById(id);
        model.addAttribute("user",user);
        return "update";
    }

    @RequestMapping("update")
    public String update(User user){
        userService.update(user);
        return "redirect:/findAll";
    }
    @RequestMapping("delete")
    public String delete(Long id){
        userService.delete(id);
        return "redirect:/findAll";
    }
}
